package com.cloud.school.bus.teacherhelper.protocol.classstudent;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;

import android.os.Environment;

import com.android.support.jhf.utils.FileUtils;
import com.cloud.school.bus.teacherhelper.entitys.ClassInfo;
import com.cloud.school.bus.teacherhelper.entitys.Student;
import com.cloud.school.bus.teacherhelper.entitys.Teacher;
import com.cloud.school.bus.teacherhelper.protocol.baseresponse.BaseJsonHttpResponse;

public class GetClassinfoResponse extends BaseJsonHttpResponse {

	protected Teacher teacher;
	protected ClassInfo classInfo;
	protected List<Student> studentList = new ArrayList<Student>();

	@Override
	public void onSuccess(int statusCode, Header[] headers,
			String responseString) throws Throwable {

		if ("1".equals(code)) {
			JSONObject mainJsonObject = new JSONObject(responseString);
			JSONObject teacherJsonObject = mainJsonObject
					.optJSONObject("teacher");
			if (null != teacherJsonObject) {
				teacher = new Teacher();
				teacher.teacherid = teacherJsonObject
						.optString("teacherid", "");
				teacher.sex = teacherJsonObject.optString("sex", "");
				teacher.nikename = teacherJsonObject.optString("nikename", "");
				teacher.ismainid = teacherJsonObject.optString("ismainid", "");
				teacher.avatar = teacherJsonObject.optString("avatar", "");
				teacher.mobile = teacherJsonObject.optString("mobile", "");
				teacher.teachername = teacherJsonObject.optString(
						"teachername", "");
			}

			JSONArray studentJsonArray = mainJsonObject
					.optJSONArray("studentinfo");
			if (null != studentJsonArray) {
				for (int i = 0; i < studentJsonArray.length(); i++) {
					JSONObject itemJsonObject = studentJsonArray
							.optJSONObject(i);
					if (null != itemJsonObject) {
						Student student = new Student();
						student.birthday = itemJsonObject.optString("birthday",
								"");
						student.sex = itemJsonObject.optString("sex", "");
						student.absence = itemJsonObject.optString("absence",
								"");
						student.parentid = itemJsonObject.optString("parentid",
								"");
						student.uid_student = itemJsonObject.optString(
								"uid_student", "");
						student.avatar = itemJsonObject.optString("avatar", "");
						student.studentno = itemJsonObject.optString(
								"studentno", "");
						student.online = itemJsonObject.optString("online", "");
						student.username = itemJsonObject.optString("username",
								"");
						student.isattendance = itemJsonObject.optString(
								"isattendance", "");
						student.orderendtime = itemJsonObject.optString(
								"orderendtime", "");
						student.age = itemJsonObject.optString("age", "");
						student.cnname = itemJsonObject.optString("cnname", "");
						student.ordertitle = itemJsonObject.optString(
								"ordertitle", "");
						student.isabsence = itemJsonObject.optString(
								"isabsence", "");
						student.enname = itemJsonObject.optString("enname", "");
						student.mobile = itemJsonObject.optString("mobile", "");
						student.studentid = itemJsonObject.optString(
								"studentid", "");
						studentList.add(student);
					}
				}
			}

			JSONObject classinfoJsonObject = mainJsonObject
					.optJSONObject("classinfo");
			if (null != classinfoJsonObject) {
				classInfo = new ClassInfo();
				classInfo.uid = classinfoJsonObject.optString("uid", "");
				classInfo.phone = classinfoJsonObject.optString("phone", "");
				classInfo.schoolname = classinfoJsonObject.optString(
						"schoolname", "");
				classInfo.address = classinfoJsonObject
						.optString("address", "");
				classInfo.classname = classinfoJsonObject.optString(
						"classname", "");
				classInfo.province = classinfoJsonObject.optString("province",
						"");
				classInfo.city = classinfoJsonObject.optString("city", "");
				classInfo.classid = classinfoJsonObject
						.optString("classid", "");
			}

		}
	}

}
